package cn.tedu.egmvc02.controller;

import cn.tedu.egmvc02.mapper.AddressMapper;
import cn.tedu.egmvc02.pojo.entity.Address;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/v1/address/")
public class AddressController {
    @Autowired
    private AddressMapper addressMapper;
    @RequestMapping("insert")
    public String insert(Address  add){
        Address address = new Address();
        BeanUtils.copyProperties(add,address);
        addressMapper.insert(address);
        System.out.println("AddressController:"+address);
        return "插入成功";
    }

    @RequestMapping("select")
    public List<Address> addressList(){

        return addressMapper.addressList();
    }

    @RequestMapping("delete")
    public String delete(Long id){
        addressMapper.delete(id);
        return "删除成功";
    }

    @RequestMapping("update")
    public String update(Address address){
        addressMapper.update(address);
        return "更新成功";
    }



}
